package com.tsl.prevention.modules.user.controller;


import com.tsl.prevention.modules.user.dto.BuyRecordDTO;
import com.tsl.prevention.modules.user.entity.Buyrecord;
import com.tsl.prevention.modules.user.service.IBuyrecordService;
import com.tsl.prevention.util.Result;
import com.tsl.prevention.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lionel
 * @since 2021-03-25
 */
@RestController
@RequestMapping("/user/buyrecord")
@Api
public class BuyrecordController {
    @Autowired
    IBuyrecordService iBuyrecordService;

    @PostMapping("/add")
    @ApiOperation("增加数组")
    public Result add(@RequestBody BuyRecordDTO[] buyRecordDTOS) {

        String buyid = StringUtil.getGUID();
        for (BuyRecordDTO buyRecordDTO : buyRecordDTOS) {
//            System.out.println(buyRecordDTO);
            //获取商品id
            Buyrecord buyrecord = new Buyrecord();
            buyrecord.setNum(buyRecordDTO.getNum());
            buyrecord.setGoodsId(buyRecordDTO.getId());
            buyrecord.setFee(buyRecordDTO.getPrice());
            buyrecord.setBuyId(buyid);
            iBuyrecordService.save(buyrecord);
        }
        return Result.create();
    }
}

